<!--
  运营-招聘管理-【职位应聘】-职位下投递的简历列表
 -->
<template>
  <div class="app-container">
    <el-form
      ref="rightQueryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="投递时间" prop="date">
        <el-date-picker
          v-model="queryParams.date"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item label="投递状态" prop="status">
        <el-select v-model="queryParams.status">
          <el-option
            v-for="(item, ind) in resumeStatus"
            :key="ind"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="学生名称" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生名称"
          clearable
        />
      </el-form-item>
      <el-form-item label="来源" prop="source">
        <el-select v-model="queryParams.source">
          <el-option
            v-for="(item, ind) in resumeSource"
            :key="ind"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="收藏" prop="collectStatus">
        <el-select v-model="queryParams.collectStatus">
          <el-option label="不限" :value="null"/>
          <el-option label="是" value="1"/>
          <el-option label="否" value="0"/>
        </el-select>
      </el-form-item>
      <el-form-item label="求职状态" prop="jobStatus">
        <el-select v-model="queryParams.jobStatus">
          <el-option label="不限" :value="null"/>
          <el-option label="正在实习" value="正在实习"/>
          <el-option label="暂无实习" value="暂无实习"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" type="index" />
      <el-table-column label="姓名" align="center" prop="studentName" />
      <el-table-column label="年龄" align="center" prop="birthday">
        <template slot-scope="scope">
          {{ getAgeStr(scope.row.birthday) }}
        </template>
      </el-table-column>
      <el-table-column label="学历" align="center" prop="educationalBackground" />
      <el-table-column label="学校" align="center" prop="schoolName" />
      <el-table-column label="所学专业" align="center" prop="major" />
      <el-table-column label="性别" align="center" prop="sex" />
      <el-table-column label="居住地" align="center" prop="liveCity" />
      <el-table-column label="来源" align="center" prop="source">
        <template slot-scope="scope">
          {{ getSource(scope.row.source) || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="收藏" align="center" prop="collectStatus">
        <template slot-scope="scope">
          {{ ['否','是'][scope.row.collectStatus] || '否' }}
        </template>
      </el-table-column>
      <el-table-column label="最新备注" align="center" prop="remarks">
        <template slot-scope="scope">
          {{ scope.row.remarks || '--' }}
        </template>
      </el-table-column>
      <el-table-column label="求职状态" align="center" prop="jobStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.jobStatus">{{scope.row.jobStatus}}/</span>
          <span>{{scope.row.inJobTime || '--'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ getDeliverStatus(scope.row.status) }}
        </template>
      </el-table-column>
      <el-table-column
        label="投递日期"
        align="center"
        prop="postDate"
        width="180"
        sortable
      >
        <template slot-scope="scope">
          <span>{{ moment(scope.row.postDate).format('yyyy-MM-DD') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCheck(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { checkResumeFromJob } from '@/api/school-admin-api/hireManage/index.js'
import { resumeStatus, getDeliverStatus } from '@/utils/frontDataDict.js'
import { getAge } from '@/utils/utils'
import moment from 'moment'
export default {
  name: 'JobObjective',
  components: {
  },
  data() {
    return {
      moment: moment,
      getDeliverStatus: getDeliverStatus,
      resumeStatus: resumeStatus, // 职位上下架状态
      resumeSource:[
        {
          label: '不限',
          value: null
        },
        {
          label: '自主投递',
          value: '1'
        },
        {
          label: '平台推荐',
          value: '2'
        },
        {
          label: '企业邀请',
          value: '3'
        }
      ],
      // 遮罩层
      loading: true,
      // 简历列表-总条数
      total: 0,
      // 简历列表列表
      list: [],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        studentName: '',
        jobId: '',
        collectStatus: null,
        jobStatus: null,
        source: null,
        date: []
      }
    }
  },
  created() {
    this.queryParams.jobId = localStorage.getItem('jobObjective-jobId') || ''
    this.getList()
  },
  methods: {
    getSource(value){
      if(!value) return '--'
      return this.resumeSource.filter(v => v.value == value)[0].label
    },
    getAgeStr(date) {
      return getAge(date)
    },
    // 未发布列表数据
    getList() {
      this.loading = true
      // 处理查询参数
      const params = JSON.parse(JSON.stringify(this.queryParams))
      if (Array.isArray(params.date) && params.date.length === 2) {
        params.beginPostDate = params.date[0]
        params.endPostDate = params.date[1]
      }
      delete params.date
      // 执行查询
      checkResumeFromJob(params).then((response) => {
        const list = response.data.list.map(item => {
          // try {
          //   const education = JSON.parse(item.educationalExperience) ? JSON.parse(item.educationalExperience)[0] : {}
          //   item.schoolName = education?.schoolName || '--'
          //   item.major = education?.major || '--'
          //   item.educationalBackground = education.educationalBackground || '--'
          // } catch (error) {
          //   item.schoolName = '--'
          //   item.major = '--'
          //   item.educationalBackground = '--'
          // }
          if (
            Array.isArray(item.educationalExperience) &&
            item.educationalExperience.length
          ) {
            const educate = ['大专', '本科', '硕士', '博士']
            educate.map((iten) => {
              const matchEducate = item.educationalExperience.find(
                (single) => single.educationalBackground.indexOf(iten) > -1
              )
              if (matchEducate) {
                item.schoolName = matchEducate.schoolName // 学校名称
                item.major = matchEducate.major // 专业
                item.educationalBackground = iten
                // item.education = iten // 学历
              }
            })
          } else {
            item.schoolName = '--' // 学校名称
            item.major = '--' // 专业
            item.educationalBackground = '--' // 学历
          }
          return item
        })
        this.list = list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    // 重制搜索条件
    resetQuery() {
      this.resetForm('rightQueryForm')
      this.handleQuery()
    },
    /** 打开应聘详情 */
    handleCheck(row) {
      this.$emit('checkDetail', row)
    }
  }
}
</script>
